package cn.ruleengine.web.service.ruleset.impl;

import cn.ruleengine.web.service.ruleset.RuleEngineRuleSetService;
import cn.ruleengine.web.store.entity.RuleEngineRuleSet;
import cn.ruleengine.web.store.manager.RuleEngineRuleSetManager;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.google.common.collect.Maps;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * SlaServiceDeleteDTO
 * Copyright (c) 2021 WeiMai Technology, Inc.
 * All Rights Reserved.
 * Choice Proprietary and Confidential.
 *
 * @author: songyang
 * @date: 2021/8/3
 * @Description:
 */
@Service
public class RuleEngineRuleSetServiceImpl implements RuleEngineRuleSetService {

    @Resource
    private RuleEngineRuleSetManager ruleEngineRuleSetManager;

    @Override
    public Map<Long, String> getAllRuleSetMap() {
        LambdaQueryWrapper<RuleEngineRuleSet> wrapper = new LambdaQueryWrapper();
        wrapper.orderByDesc(RuleEngineRuleSet::getUpdateTime);
        List<RuleEngineRuleSet> ruleEngineRuleSets = this.ruleEngineRuleSetManager.list(wrapper);
        Map<Long, String> map = Maps.newHashMap();
        if (CollectionUtils.isNotEmpty(ruleEngineRuleSets)) {
            map = ruleEngineRuleSets.stream().collect(Collectors.toMap(RuleEngineRuleSet::getId,
                    RuleEngineRuleSet::getCode, (v1, v2) -> v2));
        }
        return map;
    }
}
